package com.xuecheng.content.api;



import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.DeleteTeachplanDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程计划管理相关接口
 */
@RestController
@Slf4j
@Api(value = "课程计划编辑接口", tags = "课程计划编辑接口")
public class TeachplanController {
    @Autowired
    TeachplanService teachplanService;



    @ApiOperation("查询课程计划树形结构")
    @ApiImplicitParam(value = "courseId", name = "课程基础Id值", required = true, dataType = "Long", paramType = "path")
    @GetMapping("teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId) {
        return teachplanService.findTeachplanTree(courseId);
    }

    @ApiOperation("课程计划创建或修改")
    @PostMapping("/teachplan")
    public void saveTeachplan( @RequestBody SaveTeachplanDto teachplan){
        teachplanService.saveTeachplan(teachplan);
    }


    /**
     * 删除课程计划
     * @param teachplanId
     * @return
     */
    @ApiOperation("课程计划删除")
    @DeleteMapping("/teachplan/{teachplanId}")
    public void deleteTeachplan(@PathVariable @Validated Long teachplanId){
        teachplanService.deleteTeachplan(teachplanId);
        System.out.println("删除课程计划");
    }

    /**
     * 课程计划向下移动
     * @param teachplanId
     */
    @ApiOperation("课程计划向下移动")
    @PostMapping("/teachplan/movedown/{teachplanId}")
    public void moveDown(@PathVariable Long teachplanId){
        teachplanService.moveDown(teachplanId);
        System.out.println("向下移动");
    }

    /**
     * 课程计划向上移动
     * @param teachplanId
     */
    @ApiOperation("课程计划向上移动")
    @PostMapping("/teachplan/moveup/{teachplanId}")
    public void moveUp(@PathVariable Long teachplanId){
        teachplanService.moveUp(teachplanId);
        System.out.println("向上移动");
    }

    /**
     * 课程计划和媒资文件绑定
     * @param bindTeachplanMediaDto
     */
    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
    teachplanService.associationMedia(bindTeachplanMediaDto);
    
    }


}
